package com.example.admin_oa.exception;

import com.example.comment_oa.response.AjaxResponse;
import com.example.comment_oa.response.CustomError;
import com.example.comment_oa.response.CustomErrorType;
import io.jsonwebtoken.MalformedJwtException;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.ExpiredCredentialsException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author cjl
 */
@Slf4j
@RestControllerAdvice
public class Globalexception {
    @ExceptionHandler(value = IncorrectCredentialsException.class)
    public AjaxResponse handler(IncorrectCredentialsException e) {
        System.out.println("密码错误！");
        return AjaxResponse.error(new CustomError(CustomErrorType.USER_PASSWORD, "账号或密码错误！"));
    }
    @ExceptionHandler(value = UnknownAccountException.class)
    public AjaxResponse handler(UnknownAccountException e) {
        System.out.println("账号错误！");
        return AjaxResponse.error(new CustomError(CustomErrorType.USER_PASSWORD, "账号或密码错误！"));
    }

    @ExceptionHandler(value = AuthorizationException.class)
    public AjaxResponse handler(AuthorizationException e) {
        System.out.println("无权限！");
        return AjaxResponse.error(new CustomError(CustomErrorType.Authorization, "12345"));
    }
//
//    @ExceptionHandler(value = MalformedJwtException.class)
//    public Result handler(MalformedJwtException e){
//        System.out.println("jwt错误");
//        return new Result().setCode(401).setMessage("jwt错误！");
//    }
//    io.jsonwebtoken.MalformedJwtException:   JWT格式不对
}
